package com.ybf.api.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.github.pagehelper.PageHelper;
import com.ybf.api.entity.PageRequest;
import com.ybf.api.entity.PageResult;
import com.ybf.api.entity.Role;
import com.ybf.api.mapper.RolesMapper;
import com.ybf.api.service.RolesService;
import com.ybf.api.utils.EncryptUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ybf
 * @since 2024-09-26
 */
@Service("RolesService")
public class RolesImpl implements RolesService {

    @Resource
    private RolesMapper rolesMapper;

    @Override
    public PageResult<Role> list(Role role, PageRequest pageRequest) {
        PageHelper.startPage(pageRequest);
        List<Role> roleList = rolesMapper.list(role);
        PageResult<Role> pageResult = new PageResult<Role>(roleList);
        return pageResult;
    }

    @Override
    public Role info(Integer id) {
        return rolesMapper.info(id);
    }

    @Override
    public Boolean delete(Integer id) {
        return rolesMapper.delete(id) > 0;
    }

    @Override
    public Integer edit(Role role) {
        if (role.getId() != null) {
            return rolesMapper.edit(role);
        }
        return rolesMapper.add(role);
    }
}
